package com.project.webapp.action.front.preSchool;

import com.project.dao.bean.Customer;
import com.project.service.front.preSchool.IUserLoginService;
import com.project.webapp.action.BaseAction;

/**
 * @author Sn
 * 登录Action 实作
 *
 */
public class UserLoginAction extends BaseAction 
{
	/**
	 * 序列化版本號
	 */
	private static final long serialVersionUID = 4196075238146541629L;
	private IUserLoginService iUserLoginService;
	private Customer customer;
	//错误讯息
	private String msg;
	
	//登录方法
	public String execute() throws Exception 
	{

		int str=iUserLoginService.login(customer);

		if (str==1)
		{
			session.put("user", customer);
			return SUCCESS;
			
		}else if (str==2)
		{
			msg="<script type='text/javascript'>alert('登录密码错误！');</script>";
			return "loginfail";
			
		}else if (str==3)
		{
			msg="<script type='text/javascript'>alert('用户名不存在！');</script>";
			return "loginfail";
			
		}else if (str==4)
		{
			msg="<script type='text/javascript'>alert('登录异常！');</script>";
			return "loginfail";
			
		}else 
		{			
			return "loginfail";
		}
	}
	
	//注销当前用户的方法
	public String loginout()
	{
		session.remove("user");
		return SUCCESS;
	}	
	
	public IUserLoginService getiUserLoginService() {
		return iUserLoginService;
	}
	public void setiUserLoginService(IUserLoginService iUserLoginService) {
		this.iUserLoginService = iUserLoginService;
	}
	public Customer getCustomer() {
		return customer;
	}
	public void setCustomer(Customer customer) {
		this.customer = customer;
	}
	public String getMsg() {
		return msg;
	}
	public void setMsg(String msg) {
		this.msg = msg;
	}
		
}
